---@class GT.ui.control.model : GT.ui
---@field u table<RoleID,GT.ui.control.model> 玩家独立数据驱动
---@field binding GT.ui.control.model
GT.ui.control.model = class(GT.ui, false)


---@class ui_data_model : ui_data
---@field model_id Int32 模型id
---@field color color 模型id
---@field fov Float 镜头范围
---@field m_pos vec3 镜头坐标
---@field revolve vec3  镜头旋转
---@field focus_pos vec3 镜头焦点


--- 创建图标
---@param data ui_data_model
---@return GT.ui.control.model
function GT.ui.control.model:ctor(data)
    data.class=GT.ui.control.model
    if data.uid ~= nil then
        super(self, data)
    else
        data.u_type = GT.ui.type.model
        self.model_id = data.model_id
        self.color = data.color
        self.m_pos = data.m_pos
        self.revolve = data.revolve
        self.focus_pos = data.focus_pos
        --创建控件
        super(self, data)
        if self.model_id then
            self:set_model_id(self.model_id)
        end
        if self.color then
            self:set_background_color(self.color)
        end
        if self.fov then
            self:set_fov(self.fov)
        end

        if self.m_pos then
            self:set_showroom_cposition(self.m_pos)
        end

        if self.revolve then
            self:change_showroom_crotation(self.revolve)
        end

        if self.focus_pos then
            self:set_focus_pos(self.focus_pos)
        end
    end
    self:model_watch()
    return self
end

---转对象
---@param data ui_data_model
---@return GT.ui.control.model
function GT.ui.control.model.obj(data)
    return new(GT.ui.control.model, data)
end

--监听绑定
---@return GT.ui.control.model
function GT.ui.control.model:model_watch()
    ---@type GT.ui.control.model
    self.binding=self.bind.bindable

    ---@type bind_data
    local data = {
        {
            key = "model_id",
            func = function(val, old)
                self.model_id = val
                self:set_model_id(self.model_id)
            end
        },
        {
            key = "color",
            func = function(val, old)
                self.color = val
                self:set_background_color(self.color)
            end
        },
        {
            key = "fov",
            func = function(val, old)
                self.fov = val
                self:set_fov(self.fov)
            end
        },
        {
            key = "m_pos",
            func = function(val, old)
                self.m_pos = val
                self:set_showroom_cposition(self.m_pos)
            end
        },
        {
            key = "revolve",
            func = function(val, old)
                self.revolve = val
                self:change_showroom_crotation(self.revolve)
            end
        },
        {
            key = "focus_pos",
            func = function(val, old)
                self.focus_pos = val
                self:set_focus_pos(self.focus_pos)
            end
        },


    }
    self.bind:add(data)
    return self
end

--- 设置UI模型控件ID
---@param model_id Int32 模型id
function GT.ui.control.model:set_model_id(model_id)
    game_api.set_ui_model_id(self.player.player , self.uid, model_id)
    return self
end

--- 设置ui模型控件背景色
---@param color color
---@return GT.ui.control.model
function GT.ui.control.model:set_background_color(color)
    game_api.set_show_room_background_color(self.player.player , self.uid, color.r, color.g, color.b, color.a)
    return self
end

--- 设置观察模型视野范围
---@param fov Float fov
function GT.ui.control.model:set_fov(fov)
    game_api.change_showroom_fov(self.player.player , self.uid, fov)
    return self
end

--- 设置观察模型镜头坐标
---@param pos vec3
---@return GT.ui.control.model
function GT.ui.control.model:set_showroom_cposition(pos)
    game_api.change_showroom_cposition(self.player.player , self.uid, pos.x, pos.y, pos.z)
    return self
end

--- 设置观察模型镜头旋转
---@param revolve vec3
---@return GT.ui.control.model
function GT.ui.control.model:change_showroom_crotation(revolve)
    game_api.change_showroom_crotation(self.player.player , self.uid, revolve.x, revolve.y, revolve.z)
    return self
end

--- 设置UI控件模型焦点
---@param focus_pos vec3
---@return GT.ui.control.model
function GT.ui.control.model:set_focus_pos(focus_pos)
    game_api.set_ui_model_focus_pos(self.player.player , self.uid, focus_pos.x, focus_pos.y, focus_pos.z)
    return self
end
